import { getUserProfile } from '@/api/user'
import { getToken, setToken, removeToken } from '@/utils/auth'
export default {
  namespaced: true,
  state: {
    token: getToken() || '',
    userInfo: {}
  },
  mutations: {
    //
    updateToken(state, token) {
      state.token = token
      setToken(token)
    },

    //
    delToken(state) {
      state.token = ''
      removeToken()
    },
    updateUserInfo(state, info) {
      state.userInfo = info
    },
    delUserInfo(state) {
      state.userInfo = {}
    }

  },
  actions: {
    async getUserInfo(context) {
      try {
        const res = await getUserProfile()
        console.log('getUserProfile-res', res)
        context.commit('updateUserInfo', res.data)
      } catch (error) {
        console.log(error)
      }
    }
  }
}
